<?php
/**
 * Created By PhpStorm
 * Author: patrick wu
 * Date: 2020/10/10
 * Time: 17:56
 */
namespace App\Http\Model\Mysql;

use Illuminate\Database\Eloquent\Model;

class BoxModel extends Model
{
    const IS_DELETE     =   1,
        NOT_DELETE      =   0;

    protected $table    =   'mini_box';

    protected $guarded  =   [];

    protected $dateFormat   =   'U';

    /**
     * 有效的盒子
     * @param $query
     */
    public function scopeStand($query)
    {
        $query->where(['is_delete' => self::NOT_DELETE]);
    }

    /**
     * 定义连接盒子地区表
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function area()
    {
        return $this->hasOne(BoxAreaModel::class, 'id', 'area_id');
    }

    /**
     * 定义连接盒子用户表
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function owner()
    {
        return $this->hasOne(BoxOwnerModel::class, 'id', 'owner_id');
    }

}

